﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.DAL;
using Touch2Like.Model;

namespace Touch2Like.Web.Touch2Rate
{
    public partial class Redeem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CouponRedeemDAL redeem = new CouponRedeemDAL();
            CouponRedeemInfo info = redeem.GetByCouponCode(Request["couponcode"]);

            if (info != null)
            {
                if (info.IsRedeemed == 0)
                {
                    info.IsRedeemed = 1;
                    info.RedeemDate = DateTime.Now;

                    redeem.Update(info);
                    lb_Msg.Text = "<div class='alert alert-success'><img src=" + info.CouponCodeLocation.ToString() + "></img><h2>Verified.</h2></div>";
                }
                else if (info.IsRedeemed == 1)
                {
                    lb_Msg.Text = "<div class='alert alert-error'><h2>This code has been redeemed already.</h2></div>";
                }
            }
            else 
            {
                lb_Msg.Text = "<div class='alert alert-error'><h2>Failed</h2></div>";
            }
        }
    }
}